package cn.wenlihelp.service.impl;

import cn.wenlihelp.bean.ResourceType;
import cn.wenlihelp.mapper.ResourceTypeMapper;
import cn.wenlihelp.service.ResourceTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ResourceTypeServiceImpl implements ResourceTypeService {
    @Resource
    private ResourceTypeMapper resourceTypeMapper;

    @Override
    public PageInfo<ResourceType> findAll(int page, int limit, ResourceType resourceType) {
        PageHelper.startPage(page, limit);
        List<ResourceType> resourceTypes = this.findAll(resourceType);
        return new PageInfo<>(resourceTypes);
    }

    @Override
    public List<ResourceType> findAll(ResourceType resourceType) {
        return resourceTypeMapper.findAll(resourceType);
    }

    @Override
    public ResourceType findById(Long id) {
        return resourceTypeMapper.selectByPrimaryKey(id);
    }

    @Override
    public boolean deleteByIds(Integer[] ids) {
        try {
            resourceTypeMapper.deleteByIds(ids);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public boolean insert(ResourceType resourceType) {
        try {
            return resourceTypeMapper.insertSelective(resourceType) > 0;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public boolean updateByPrimaryKey(ResourceType resourceType) {
        try {
            return resourceTypeMapper.updateByPrimaryKeySelective(resourceType) > 0;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
